package csu.web.mypetstore.web.servlet;

import com.alibaba.fastjson.JSON;
import csu.web.mypetstore.domain.*;
import csu.web.mypetstore.service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;

public class RemoveCartServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        AddCart addCart = (AddCart) session.getAttribute("addCart");
        String itemId = req.getParameter("itemId");
        addCart.removeItemById(itemId);

        String result = JSON.toJSONString(addCart.getSubTotal());
        System.out.println(result);
        resp.setContentType("text/json");
        PrintWriter out = resp.getWriter();
        out.println(result);


    }
}
